package com.neu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.po.Checkin;
import com.neu.po.ResponseResult;
import com.neu.service.CheckinSerivce;

@RestController
@RequestMapping("Checkin")
public class CheckinController {
	
	@Autowired
	private CheckinSerivce checkinSerivce;
	
	//插入入住
	@RequestMapping("insert")
	public ResponseResult insert(@RequestBody Checkin checkin ) {
		ResponseResult result =new ResponseResult();
		checkin.setDelmark(1);
		result.setData(checkinSerivce.insert(checkin));
		return result;
		
	}
	//按房间编号和随机生成编号和姓名查找
	@RequestMapping("select")
	public ResponseResult select(String checkinId ) {
		ResponseResult result =new ResponseResult();
		boolean b = CheckinController.isNumeric(checkinId);
		if(b) {
			int a = Integer.parseInt(checkinId);
			result.setData(checkinSerivce.select(a));
		}else {
			result.setData(checkinSerivce.selectString(checkinId));
		}
		
		return result;
		
	}
	
	public static boolean isNumeric(String str){
		  for (int i = str.length();--i>=0;){  
		   if (!Character.isDigit(str.charAt(i))){
		    return false;
		   }
		  }
		  return true;
		}
}
